# -*- coding: utf-8 -*-
import os
import random
import shutil

def getDirImageNum(ImgPath, TxtPath):
    bmpDirImagesNum = 0
    for bmpfile in os.listdir(ImgPath):
        if os.path.splitext(bmpfile)[1] == '.png':
            bmpDirImagesNum += 1
            with open (TxtPath,'a') as f:
                f.write(ImgPath+bmpfile+'\n')
    print(bmpDirImagesNum)

path = 'padocr_label.txt' #原txt绝对路径
path2 = '/mnt/hd02/cwh/slot_img/' #照片新移动的绝对路径，注意最后面的‘/’
path3 = '/mnt/hd02/cwh/slot_img/val_new.txt' #照片新移动的txt绝对路径
if not os.path.exists(path2):
    os.makedirs(path2)

count = 0
with open(path,'r')as f:
    for line in f:
        count=count+1
        out_image=line.split('.png')[0]+".png"
        out_txt=line.split('.png')[0]+".txt"  
        shutil.copy(out_image, path2)
        shutil.copy(out_txt, path2)

getDirImageNum(path2, path3)